<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {

	public function index()
	{
		$data['main_content'] = 'login/login.php';
		$this->load->view('includes/template.php',$data);
	}

	function validate_login(){
		$this->load->library('form_validation');
		$this->load->model('login_model');
		$this->form_validation->set_error_delimiters('<div class="col-sm-6"><div class="alert alert-danger alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>', '</div></div>');
		
		$this->form_validation->set_rules('username', 'Username', 'required');
		$this->form_validation->set_rules('password', 'Password', 'required');
		
		if ($this->form_validation->run() == FALSE){
			$this->index();
		}else{
			$user_session = $this->login_model->validate();
			if (is_array($user_session)) {
				$this->session->set_userdata($user_session);
				redirect('/tasks');
			}else{
				$this->index();
			}
		}
	}

}

/* End of file login.php */
/* Location: ./application/controllers/login.php */


